package com.xunlai.infra.permission.business.controller;

import com.xunlai.infra.permission.business.service.AdPictureService;
import com.xunlai.infra.permission.business.vo.ad.AdPictureCreateVo;
import com.xunlai.infra.permission.business.vo.ad.AdPictureListVo;
import com.xunlai.infra.permission.common.vo.BasePageRespVo;
import com.xunlai.infra.permission.common.vo.BaseResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liang
 * @date 9/25/23 9:27 PM
 */
@RestController
@RequestMapping("travel/manage/ad/picture")
public class AdPictureManageController {

    private AdPictureService adPictureService;

    @PostMapping("create")
    public BaseResponse<Long> create(@RequestBody AdPictureCreateVo adPictureCreateVo){
        return BaseResponse.success(adPictureService.createAdPicture(adPictureCreateVo));
    }

    @DeleteMapping("delete/{id}")
    public  BaseResponse<Void> delete(@PathVariable Long id){
        adPictureService.deleteAdPicture(id);
        return BaseResponse.success();
    }

    @GetMapping("list")
    public BaseResponse<BasePageRespVo<AdPictureListVo>> list(@RequestParam(required = false,defaultValue = "1") Integer pageNum,
                                                              @RequestParam(required = false,defaultValue = "10") Integer pageSize){
        return BaseResponse.success(adPictureService.listAdPicture(pageNum,pageSize));
    }

    @GetMapping("active/all")
    public BaseResponse<List<AdPictureListVo>> listAllActive(){
        return BaseResponse.success(adPictureService.listAllActiveAdPicture());
    }

    @PutMapping("active/{id}")
    public BaseResponse<Void> active(@PathVariable Long id){
        adPictureService.changeActiveStatus(id,true);
        return BaseResponse.success();
    }

    @PutMapping("deactivate/{id}")
    public BaseResponse<Void> deactivate(@PathVariable Long id){
        adPictureService.changeActiveStatus(id,false);
        return BaseResponse.success();
    }

    @Autowired
    public void setAdPictureService(AdPictureService adPictureService) {
        this.adPictureService = adPictureService;
    }
}
